/**
 * avImgThrd.h
 */

#ifndef __IMGTHRD_H__
#define __IMGTHRD_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <xdc/std.h>
#include <ti/sdo/ce/CERuntime.h>
#include <ti/sdo/ce/Engine.h>
#include <ti/sdo/ce/osal/Memory.h>
#include <ti/sdo/ce/video/videnc.h>
#include <ti/sdo/ce/image/imgenc.h>
#include <ti/sdo/ce/trace/gt.h>

#include <stdio.h>
#include <stdbool.h>
#include <semaphore.h>

#include <Base.h>
#include "../alarm/alarmInterlock.h"
#include "avStruct.h"
#include "avEncBuffs.h"

typedef struct {
	IMGENC_Handle hIE;
	EncBuffs buffs;
	SSParam ssParam;	// for alarm snapshot only
	Capturer *pCapturer;	// for scheme snapshot only
	pthread_t tid;
	bool snapshoting;		// current snapshot status
	pthread_mutex_t lock;
} ImgEncEnv;

/**
 * create image encoder
 * @param
 *		hCE		input	code engine handler
 *		pName	input	image encode name
 *		pParam	input	av param
 * @return
 *		image encoder handler or NULL when failure
 */
IMGENC_Handle createImageEncoder(Engine_Handle hCE, char *pName, Video_Param *pParam);

/**
 * configure image handle
 * @param
 *		hIE		input	image handle
 *		pParam	input	video parameter
 * @return
 *		true when configure success, else false
 */
bool confImgHdl(IMGENC_Handle hIE, Video_Param *pParam);

/**
 * clear image environment
 * @param
 *		pEnv	input	image environment pointer
 */
void cleanImgEncEnv(ImgEncEnv *pEnv);

/**
 * initialize image environment
 * @param
 *		pEnv	output	image encode environment
 *		hCE		input	code engine handler
 *		pParam	input	av parameter
 * @return
 *		true when success, else false
 */
bool initImgEncEnv(ImgEncEnv *pEnv, Engine_Handle hCE, Video_Param *pParam);

/**
 * image thread function
 * @param
 *		arg		input	chnvid pointer
 * @return
 *		NULL
 */
void *imgThrd(void *arg);

#ifdef __cplusplus
}
#endif

#endif	// __IMGTHRD_H__

